package org.jeecg.modules.system.service.impl;

import org.jeecg.common.exception.JeecgBootException;
import org.jeecg.modules.system.entity.SysPermission;
import org.jeecg.modules.system.entity.Sys_permission;
import org.jeecg.modules.system.model.TreeModel;
import org.jeecg.modules.system.service.SysPermissionService;
import org.jeecg.tools.RowMappers;
import org.springframework.jdbc.core.support.JdbcDaoSupport;

import java.util.List;

public class SysPermissionServiceImpl2 extends JdbcDaoSupport implements SysPermissionService {
    @Override
    public List<TreeModel> queryListByParentId(String parentId) {
        return null;
    }

    @Override
    public void deletePermission(String id) throws JeecgBootException {

    }

    @Override
    public void deletePermissionLogical(String id) throws JeecgBootException {

    }

    @Override
    public void addPermission(SysPermission sysPermission) throws JeecgBootException {

    }

    @Override
    public void editPermission(SysPermission sysPermission) throws JeecgBootException {

    }

    @Override
    public List<Sys_permission> queryByUser(String username) {

        String sql="SELECT data.*,sys_user.org_code scode FROM ( SELECT * FROM ( SELECT P.* FROM SYS_PERMISSION P WHERE (EXISTS( SELECT A.ID FROM SYS_ROLE_PERMISSION A JOIN SYS_ROLE B ON A.ROLE_ID = B.ID JOIN SYS_USER_ROLE C ON C.ROLE_ID = B.ID JOIN SYS_USER D ON D.ID = C.USER_ID WHERE P.ID = A.PERMISSION_ID AND D.USERNAME = '"+username+"' ) OR (P.URL LIKE '%:CODE' AND P.URL LIKE '/ONLINE%' AND P.HIDDEN = 1) OR (P.URL = '/ONLINE') ) AND P.DEL_FLAG = 0 UNION SELECT P.* FROM SYS_PERMISSION P WHERE EXISTS( SELECT A.ID FROM SYS_DEPART_ROLE_PERMISSION A JOIN SYS_DEPART_ROLE B ON A.ROLE_ID = B.ID JOIN SYS_DEPART_ROLE_USER C ON C.DROLE_ID = B.ID JOIN SYS_USER D ON D.ID = C.USER_ID WHERE P.ID = A.PERMISSION_ID AND D.USERNAME = '"+username+"' ) AND P.DEL_FLAG = 0 ) H ) data LEFT JOIN sys_user ON data.create_by = sys_user.username ";

        List list=this.getJdbcTemplate().query(sql,new RowMappers(Sys_permission.class));

        return list;
    }

    @Override
    public void deletePermRuleByPermId(String id) {

    }

    @Override
    public List<String> queryPermissionUrlWithStar() {
        return null;
    }
}
